<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
get_config_keytable("workclass_admin");
get_union_add();
empty($do) && $do = 'list';
if ($do == 'list') {
	$blog = $db->fetch_one_array("SELECT title FROM ".DB_TABLEPRE."workclass_flow WHERE template_id='".$_GET["template_id"]."' and type_id='".$_GET["type_id"]."' and unionid='".union_id."' ORDER BY id desc LIMIT 1");
	if($blog["title"]!=''){
		$wheresql = '';
		$page = max(1, getGP('page','G','int'));
		$pagesize = $_CONFIG->config_data('pagenum');
		$offset = ($page - 1) * $pagesize;
		$url = 'admin.php?ac=work_flow&fileurl=work&template_id='.$_GET["template_id"].'&type_id='.$_GET["type_id"].'';
		$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."workclass_flow WHERE template_id='".$_GET["template_id"]."' and type_id='".$_GET["type_id"]."'  and unionid='".union_id."'");
		$sql = "SELECT * FROM ".DB_TABLEPRE."workclass_flow WHERE template_id='".$_GET["template_id"]."' and type_id='".$_GET["type_id"]."' and unionid='".union_id."' ORDER BY id asc LIMIT $offset, $pagesize";
		$result = $db->fetch_all($sql);
		include_once('template/work_flow.php');
	}else{
		 $workclass_flow = array(
			'title' => '填写申请信息',
			'number' => '1',
			'type' => '0',
			'flowtype' => '2',
			'template_id' => $_GET["template_id"],
			'type_id' => $_GET["type_id"],
			'date' => get_date('Y-m-d H:i:s',PHP_TIME),
			'uid' => $_USER->id,
			'unionid' => union_id
		);
		//写入主表信息
		insert_db('workclass_flow',$workclass_flow);
		goto_page('admin.php?ac=work_flow&fileurl=work&template_id='.$_GET["template_id"].'&type_id='.$_GET["type_id"].'');
	}

} elseif ($do == '删 除') {	
	$idarr = getGP('id','P','array');
	foreach ($idarr as $id) {
		$db->query("DELETE FROM ".DB_TABLEPRE."workclass_flow WHERE id = '$id' and unionid='".union_id."'");
		$content=$id;
		$title='删除工作流程';
		get_oa_log_dbadd($id,$content,$title,35,$_USER->id);	
	}
	show_msg('工作流流程删除成功！', 'admin.php?ac=work_flow&fileurl=work&template_id='.$_GET["template_id"].'&type_id='.$_GET["type_id"].'');

}elseif ($do == 'add') {
	include_once('template/work_flow_add.php');
}elseif ($do == 'addsave') {
	$title = getGP('title','P');
	$number = getGP('number','P');
	$workuser = getGP('workuser','P');
	$type = getGP('type','P');
	$template_id = getGP('template_id','P');
	$type_id = getGP('type_id','P');
	$flowtype = getGP('flowtype','P');
	$uid = $_USER->id;
	$date=get_date('Y-m-d H:i:s',PHP_TIME);
	//主表信息
	$workclass_flow = array(
		'title' => $title,
		'number' => $number,
		'workuser' => $workuser,
		'date' => $date,
		'uid' => $uid,
		'flowtype' => $flowtype,
		'template_id' => $template_id,
		'type_id' => $type_id,
		'type' => $type,
		'unionid' => union_id
	);
	//写入主表信息
	insert_db('workclass_flow',$workclass_flow);
	$id=$db->insert_id();
	$content=$title.get_inc_log(1).$number.get_inc_log(1).$workuser.get_inc_log(1).$type.get_inc_log(1).$template_id.get_inc_log(1).$type_id.get_inc_log(1).$date.get_inc_log(1).$uid;
	$title='添加工作流流程';
	get_oa_log_dbadd($id,$content,$title,35,$_USER->id);
	show_msg('工作流流程添加成功！', 'admin.php?ac=work_flow&fileurl=work&template_id='.$template_id.'&type_id='.$type_id.'');
}elseif ($do == 'edit') {
	$id = getGP('id','G','int');
	$blog = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."workclass_flow  WHERE id = '$id' and unionid='".union_id."'");
	include_once('template/work_flow_edit.php');
}elseif ($do == 'editsave') {
	$id = getGP('id','P','int');
	$title = getGP('title','P');
	$workuser = getGP('workuser','P');
	$type = getGP('type','P');
	$template_id = getGP('template_id','P');
	$type_id = getGP('type_id','P');
	$flowtype = getGP('flowtype','P');
	//主表信息
	$workclass_flow = array(
		'title' => $title,
		'workuser' => $workuser,
		'flowtype' => $flowtype,
		'type' => $type,
		'unionid' => union_id
	);
	update_db('workclass_flow',$workclass_flow, array('id' => $id));
	$id=$db->insert_id();
	$content=$formname.get_inc_log(1).$inputname.get_inc_log(1).$inputvalue.get_inc_log(1).$type.get_inc_log(1).$inputtype.get_inc_log(1).$inputvaluenum.get_inc_log(1).$confirmation;
	$title='编辑工作流流程';
	get_oa_log_dbadd($id,$content,$title,35,$_USER->id);
    show_msg('工作流流程编辑成功！', 'admin.php?ac=work_flow&fileurl=work&template_id='.$template_id.'&type_id='.$type_id.'');
}
?>